package com.yhq.sensitive.controller;

import com.alibaba.fastjson2.JSONObject;
import com.yhq.sensitive.enums.Date;
import com.yhq.sensitive.util.KeyWordFilter;

import org.springframework.web.bind.annotation.*;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;


@RestController
@RequestMapping("/yikData")
public class TestController {





    @GetMapping("/getKeyPhraseExtraction")
    public JSONObject getKeyPhraseExtraction(String rwords) throws UnsupportedEncodingException {
        JSONObject json= new JSONObject();
        HashMap<String, String> keyMap = new HashMap<>();
        keyMap.put("date","src/main/resources/Date.txt");
        keyMap.put("region","src/main/resources/Region.txt");
        keyMap.put("model","src/main/resources/KeyPhraseExtraction.txt");
        for (String key : keyMap.keySet()) {
           json.put(key, getJsonDate(rwords,  keyMap.get(key),key));
        }
        return json;
    }

    public  JSONObject getJsonDate( String rwords, String path,String name){
        JSONObject json= new JSONObject();
        KeyWordFilter keyWordFilter = new KeyWordFilter(path);
        Set<String> sensitiveWord = keyWordFilter.getSensitiveWord(rwords, 2);
        for (int i=0;i<sensitiveWord.size();i++) {
            json.put(name+i,sensitiveWord.toArray()[i]);
        }
        return  json;
        }


}
